package com.ruoyi.common.core.domain.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseIdEntity;
import com.ruoyi.common.enums.PayStatusEnum;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;

/**
 * 会员购买订单对象 yh_order
 * 
 * @author ruoyi
 * @date 2023-06-06
 */
@Data
@ApiModel(value = "YhOrder", description = "会员购买订单对象")
public class YhOrder extends BaseIdEntity
{
    private static final long serialVersionUID = 1L;

    /** ID */
    @ApiModelProperty("ID")
    private String id;

    /** 删除标志 true/false 删除/未删除 */
    @Excel(name = "删除标志 true/false 删除/未删除")
    @ApiModelProperty("删除标志 true/false 删除/未删除")
    private boolean deleteFlag;

    /** 订单取消原因 */
    @Excel(name = "订单取消原因")
    @ApiModelProperty("订单取消原因")
    private String cancelReason;

    /** 完成时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "完成时间", width = 30, dateFormat = "yyyy-MM-dd")
    @ApiModelProperty("完成时间")
    private Date completeTime;

    /** 总价格 */
    @Excel(name = "总价格")
    @ApiModelProperty("总价格")
    private Double flowPrice;

    /** 商品价格 */
    @Excel(name = "商品价格")
    @ApiModelProperty("商品价格")
    private Double goodsPrice;

    /** 会员ID */
    @Excel(name = "会员ID")
    @ApiModelProperty("会员ID")
    private String memberId;

    /** 用户名 */
    @Excel(name = "用户名")
    @ApiModelProperty("用户名")
    private String memberName;

    /** 用户头像 */
    @Excel(name = "用户头像")
    @ApiModelProperty("用户头像")
    @TableField(exist = false)
    private String face;

    /** 订单状态 */
    @Excel(name = "订单状态")
    @ApiModelProperty("订单状态")
    private String orderStatus;

    /** 支付方式返回的交易号 */
    @Excel(name = "支付方式返回的交易号")
    @ApiModelProperty("支付方式返回的交易号")
    private String payOrderNo;

    /** 支付时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "支付时间", width = 30, dateFormat = "yyyy-MM-dd")
    @ApiModelProperty("支付时间")
    private Date paymentTime;

    /** 会员等级id */
    @Excel(name = "会员等级id")
    @ApiModelProperty("会员等级id")
    private String memberLevelRuleId;

    /** 购买会员等级 */
    @Excel(name = "购买会员等级")
    @ApiModelProperty("购买会员等级")
    private Integer memberLevel;

    /** 订单编号 */
    @Excel(name = "订单编号")
    @ApiModelProperty("订单编号")
    private String sn;

    /** 创建者 */
    @ApiModelProperty("创建者")
    @TableField(fill = FieldFill.INSERT)
    private String createBy;

    /** 创建时间 */
    @ApiModelProperty("创建时间")
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /** 更新者 */
    @TableField(fill = FieldFill.UPDATE)
    @ApiModelProperty("更新者")
    private String updateBy;

    /** 更新时间 */
    @ApiModelProperty("更新时间")
    @TableField(fill = FieldFill.UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    public <T> QueryWrapper<T> queryWrapper(){
        QueryWrapper<T> wrapper=new QueryWrapper<>();

//        wrapper.eq(deleteFlag != null,"delete_flag" , deleteFlag);
        wrapper.eq(StringUtils.isNotEmpty(cancelReason),"cancel_reason" , cancelReason);
        wrapper.eq(completeTime != null,"complete_time" , completeTime);
        wrapper.eq(flowPrice != null,"flow_price" , flowPrice);
        wrapper.eq(goodsPrice != null,"goods_price" , goodsPrice);
        wrapper.eq(memberId != null,"member_id" , memberId);
        wrapper.like(StringUtils.isNotEmpty(memberName),"o.member_name" , memberName);
        wrapper.eq(StringUtils.isNotEmpty(orderStatus),"order_status" , orderStatus);
        wrapper.eq(StringUtils.isNotEmpty(payOrderNo),"o.pay_order_no" , payOrderNo);
        wrapper.ge(paymentTime != null,"o.payment_time" , paymentTime);
        wrapper.le(paymentTime != null,"o.payment_time" , paymentTime + " 23:59:59");
        wrapper.eq(StringUtils.isNotEmpty(memberLevelRuleId),"member_level_rule_id" , memberLevelRuleId);
        wrapper.eq(memberLevel != null,"o.member_level" , memberLevel);
        wrapper.eq(StringUtils.isNotEmpty(sn),"o.sn" , sn);
        wrapper.eq("o.order_status" , PayStatusEnum.PAID.name());
        wrapper.orderByDesc("o.create_time");
        return wrapper;
    }

}
